﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model.Entity;

namespace OnlineNewsEditorial_DaoLibrary.Impl
{
    public class DivisionDao : AbstractDao<Division>
    {
        public override List<Division> getAll()
        {
            try
            {
                var q = from div in _ctx.Divisions
                        select div;
                return q.ToList<Division>();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public Division getById(String divId)
        {
            try
            {
                var q = from div in _ctx.Divisions
                        where div.divId == divId
                        select div;
                return q.Single<Division>();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public Division getByName(String divName)
        {
            try
            {
                var q = from div in _ctx.Divisions
                        where div.divName == divName
                        select div;
                return q.Single<Division>();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public List<Division> getByCategory(Category category)
        {
            try
            {
                var q = from div in _ctx.Divisions
                        where div.Categories == category
                        select div;
                return q.ToList<Division>();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public List<Division> getByJobAssignment(JobAssignment jobAssignment)
        {
            try
            {
                var q = from div in _ctx.Divisions
                        where div.JobAssignments == jobAssignment
                        select div;
                return q.ToList<Division>();
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}
